function evidencijaNewRow(btn){
	var tr = btn.parentNode.parentNode;
	var holder = tr.parentNode;
	var form = holder.parentNode.parentNode;
	
	var ntr = tr.cloneNode(true);
	holder.appendChild(ntr);
	
	var tdl = tr.getElementsByTagName("td");
	var tdl = tdl[tdl.length-1];
	var inpt = tdl.getElementsByTagName("input")[0];
	inpt.style.display="none";
	
	var td = ntr.getElementsByTagName("td")[0];
	var newIndex = parseInt(td.innerHTML)+1;
	td.innerHTML = newIndex;
	
	var inputs = ntr.getElementsByTagName("input");
	var textareas = ntr.getElementsByTagName("textarea");
	var sels = ntr.getElementsByTagName("select");
	
	for(var i=0; i<inputs.length; i++){
		if(inputs[i].type=="text" || inputs[i].type=="checkbox"){
			inputs[i].name = inputs[i].name.substr(0,inputs[i].name.lastIndexOf("_")+1)+newIndex;
			inputs[i].id = inputs[i].name;
		}
	}
	for(i=0; i<textareas.length; i++){
		textareas[i].name = textareas[i].name.substr(0,textareas[i].name.lastIndexOf("_")+1)+newIndex;
		textareas[i].id = textareas[i].name;
	}
	for(i=0; i<sels.length; i++){
		sels[i].name = sels[i].name.substr(0,sels[i].name.lastIndexOf("_")+1)+newIndex;
		sels[i].id = sels[i].name;
	}
	
	var els = form.elements;
	els.namedItem("length").value = newIndex;
	
	sels[0].focus();
	
	/*var td = ntr.getElementsByTagName("td")[1];
	var sel = td.getElementsByTagName("select")[0];
	sel.name = sel.name.substr(0,sel.name.lastIndexOf("_")+1)+newIndex;
	sel.id = sel.name;
	sel.focus();*/
}
function evidencijaDeleteRow(btn){
	var tr = btn.parentNode.parentNode;
	var holder = tr.parentNode;
	var form = holder.parentNode.parentNode;
	
	var trs = holder.getElementsByTagName("tr");
	if(trs.length>2){
		if(confirm("Potvrdite brisanje.")){
			holder.removeChild(tr);
		}else{
			return;
		}
	}
	
	var els = form.elements;
	els.namedItem("length").value = parseInt(els.namedItem("length").value)-1;
	
	var trs = holder.getElementsByTagName("tr");	
	var td = trs[trs.length-1].getElementsByTagName("td");
	td = td[td.length-1];
	var inpt = td.getElementsByTagName("input")[0];
	inpt.style.display="block";
}

function afterSaveEvidencijaDolazaka(response){
	var tmp = response.split(/\{!\}/);
	var code= parseInt(tmp[0]);
	var msg=tmp[1];
	var html=tmp[2];
	alert(msg);
	if(code){
		setContent(html);
	}
}

function evidencijaVremeNext(e,inpt){
	var keyCode = e.keyCode;
	//alert(keyCode)
	inpt.value = inpt.value.replace(/[^\d]/,"");
	
	if(inpt.value.length==2 && keyCode!=9 && keyCode!=16){
		var n=inpt.nextSibling.nextSibling.nextSibling; 
		n.focus(); 
		n.select()
	}
}

function deleteEvidencijaDolazaka(id){
	id = parseInt(id);
	if(id>0){
		if(confirm("Da li ste sigurni u vezi brisanja?")){
			LoadRSDoc("evidencija.php?a=delete&id="+id,"afterDeleteEvidencijaDolazaka");
		}
	}
}
function afterDeleteEvidencijaDolazaka(response){
	var sbmt = document.getElementById("submitBtn");
	alert(response);
	sbmt.click();
}